﻿using System;
using System.Collections;
using BEGDC.CC.Entity;
using BEGDC.CC.BL.Common;
using BEGDC.CC.BL.CCFlow.CR;
using BEGDC.Utility.Castle;

namespace BEGDC.CC.Web.UserControls.CR
{
	/// <summary>
	/// Summary description for BaseCR.
	/// </summary>
	public class BaseCR : BEGDC.CC.Web.UserControls.BaseCtrl
	{
		public BaseCR()
		{
		}

		protected void PreInitForm()
		{
			string RequestApp = Request.QueryString["AppID"];
			if( RequestApp == null || RequestApp == String.Empty ) RequestApp = "0";
			this.AppID = Convert.ToInt32( RequestApp );
			this.Application = null;

			//base.InitFlowInfo( this.ProjectId,myStep );

			if( this.AppID <0)
			{
				WebUtility.Go2ErrorPage( this.Page, "wrong Application ID" );
			}		
			if(!this.IsPostBack)
			{
				Session[SessionFlag.CustomerSession] = null;
				Session[SessionFlag.AccompanySession] = null;
				Session[SessionFlag.HotelSession] = null;
				Session[SessionFlag.CompanyCarSession] = null;
				Session[SessionFlag.LeaseCarSession] = null;
				Session[SessionFlag.AccompanySessionEZ] = null;
				Session[SessionFlag.CustomerSessionEZ] = null;
				Session[SessionFlag.CompanyCarSessionEZ] = null;
				Session[SessionFlag.LeaseCarSessionEZ] = null;
				Session[SessionFlag.HotelSessionEZ] = null;
				Session[SessionFlag.ContractInfo] = null;
				Session[SessionFlag.CostCenter] = null;
			}
		}

		protected long LoadApplication()
		{
			int appid = this.AppID;
			long flowId = 0;

			BEGDC.CC.Entity.Application app = null;

			if( appid > 0 )
			{
				ICR CRService = AppContainer.Instance[ServiceConst.CRService] as ICR;
				app = CRService.GetApplication(appid);

				if( app != null )
				{
					BEGDC.CC.Entity.FlowInstance flow = CRService.GetApplicationFlow(appid);
					if(flow!=null)
					{
						flowId = flow.FlowID;
					}
					//BindFlowInfo( project.Id, project.NBPMFlow );
				}
				else
				{
					WebUtility.Go2ErrorPage( this.Page, "Application not found!" );
					//return flowId;
				}
			}

			this.Application = app;	

			return flowId;
		}
	}
}